# -*- coding: utf-8 -*-
# filename: handle.py

import web
import json
import time
from configcenter import configCenter
class prizeDonation(object):
    def POST(self):
        try:
            web.header("Access-Control-Allow-Origin", "*")
            web.header('content-type','text/json')
            webData = web.input()
            name = webData.name
            mobile = webData.mobile
            amount = webData.amount
            remark = webData.remark
            db = web.database(dbn='mysql', host='121.201.78.13', port=3366, user='root', pw='1sc-china', db='party')
            uptime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
            db.insert('prizeinfo',  mobile=mobile, uptime=uptime, name=name,amount=amount,remark=remark)
            pr = db.select('prize', where="id = 1")
            newprize = pr[0].totalprize + int(amount)
            db.update('prize', where="id=1" , totalprize=newprize)
            result = {'result': True, 'msg': 'donate success'}
            return json.dumps(result)

        except Exception as e:
            return e.args
